<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ds猫源在线配置主页</title>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #f3f4f6;
            color: #333;
            text-align: center;
        }

        .container {
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #fff;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            max-width: 90%;
            width: 400px;
        }

        h1 {
            font-size: 24px;
            margin-bottom: 20px;
        }

        .link {
            display: inline-block;
            font-size: 16px;
            color: #007bff;
            text-decoration: none;
            margin-bottom: 10px;
            word-wrap: break-word;
        }

        .link:hover {
            text-decoration: underline;
        }

        .copy-button {
            display: inline-block;
            padding: 8px 16px;
            font-size: 14px;
            color: #fff;
            background-color: #007bff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .copy-button:hover {
            background-color: #0056b3;
        }

        .message {
            margin-top: 10px;
            font-size: 14px;
            color: #28a745;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>欢迎使用DS猫源</h1>
    <a href="#" class="link" id="link">$catLink</a>
    <button class="copy-button" id="copyButton">复制地址</button>
    <div class="message" id="message" style="display: none;">链接已复制到剪切板!</div>
</div>

<script>
    function copyToClipboard(text) {
        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text)
                .then(() => {
                    console.log('Text copied to clipboard!');
                })
                .catch(err => {
                    console.error('Failed to copy text: ', err);
                });
        } else {
            console.warn('Clipboard API not supported. Falling back to legacy method.');
            fallbackCopyToClipboard(text);
        }
    }

    function fallbackCopyToClipboard(text) {
        const textarea = document.createElement('textarea');
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        try {
            document.execCommand('copy');
            console.log('Fallback: Text copied to clipboard!');
        } catch (err) {
            console.error('Fallback: Failed to copy text: ', err);
        }
        document.body.removeChild(textarea);
    }

    document.getElementById('copyButton').addEventListener('click', function () {
        const link = document.getElementById('link').textContent;
        copyToClipboard(link);
        alert('已复制到剪切板');
    });
</script>
</body>
</html>
